(function () {
    var vm = new Vue({
        el: "#wrapper",
        data: {
            doctorid: "",
            userName: '',
            loginInfo: { isLogin: '', name: '', mobile: '' },
            deptList: [],
            titleList: [],
            dateList: [{ ActiveDate: '', DateText: '', IsDateScreenActive: '' }],
            conditionsList: [],
            doctorList: [],
            condition: { Id: '', Name: '', From: '' },
            pageInfo: {
                curPageRecord: [],
                keyWord: "",
                totalCount: "",
                pageSize: 10,
                pageCount: 10,
                pageCurrent: 1
            },
            param: {
                pageCount: '',
                curPage: '',
                pageInfo: ''
            },
            dateSatus: "",
            titleSatus: "",
            deptSatus: "",
            keyword: "",
            showPageParam: {},
            page: 1,
            pageSize: 10
        },
        components: {
            'clinic-head': clinicHead,
            'clinic-right': clinicRight,
            'clinic-foot': clinicFoot,
            'clinic-process': clinicProcess,
            'clinic-page': clinicPage
        },
        created: function () {
            var _self = this;
            //检查登录状态
            CheckLoginStatus(_self, _self.loginInfo);
        },
        mounted: function () {
            var _self = this;
            showHtml();
            //设置导航栏样式
            document.getElementById("Home").className = "invalid-nav";
            document.getElementById("OrderExpert").className = "valid-nav";
            document.getElementById("DistinctMedical").className = "invalid-nav";
            document.getElementById("MedicalWiki").className = "invalid-nav";
            document.getElementById("News").className = "invalid-nav";
            document.getElementById("AboutUs").className = "invalid-nav";

            _self.dateList = [];
            _self.dateSatus = -1;
            this.$http.get("/OrderExpert/GetActiveDateList").then(function (res) {
                for (var i = 0; i < res.body.length; i++) {
                    _self.dateList.push(res.body[i]);
                }
            });

            _self.deptList = [];
            _self.titleSatus = -1;
            this.$http.get("/OrderExpert/GetDeptList").then(function (res) {
                for (var i = 0; i < res.body.length; i++) {
                    _self.deptList.push(res.body[i]);
                }
            });

            _self.titleList = [];
            _self.deptSatus = -1;
            this.$http.get("/OrderExpert/GetTitleList").then(function (res) {
                for (var i = 0; i < res.body.length; i++) {
                    _self.titleList.push(res.body[i]);
                }
            });
            var noResult = document.getElementById("noResult");
            

            _self.pageInfo.pageCurrent = 1;
            _self.pageInfo.curPageRecord = [];
            _self.$http.post("/OrderExpert/GetAllActiveDoctorLists", _self.pageInfo).then(function (res) {
                for (var i = 0; i < res.body.curPageRecord.length; i++) {
                    _self.pageInfo.curPageRecord.push(res.body.curPageRecord[i]);
                }
                _self.pageInfo.totalCount = res.body.totalCount;
                _self.pageInfo.pageCount = res.body.pageCount;
                _self.pageInfo.pageCurrent = res.body.pageCurrent;
                _self.param.pageCount = res.body.pageCount;
                _self.param.curPage = res.body.pageCurrent;
                _self.param.pageInfo = _self.pageInfo;
                overflowEllipsis(_self);

                var param = {
                    pageCount: _self.pageInfo.pageCount,
                    curPage: _self.pageInfo.pageCurrent,
                    pageInfo: _self.pageInfo,
                    page_func: function (p_curPage, p_pageInfo) {
                        _self.pageInfo.pageCurrent = p_curPage;
                        _self.pageInfo.curPageRecord = [];
                        _self.$http.post("/OrderExpert/GetAllActiveDoctorLists", _self.pageInfo).then(function (res) {
                            for (var i = 0; i < res.body.curPageRecord.length; i++) {
                                _self.pageInfo.curPageRecord.push(res.body.curPageRecord[i]);
                            }
                            _self.pageInfo.totalCount = res.body.totalCount;
                            _self.pageInfo.pageCount = res.body.pageCount;
                            overflowEllipsis(_self);
                        });
                    }
                };
                _self.showPageParam = param;
                if (_self.pageInfo.totalCount > 0) {
                    noResult.style.display = "none";
                } else {
                    noResult.style.display = "block";
                }

                var pageBox = document.getElementById("clinic-page-box");
                if (_self.pageInfo.pageCount === 1 || _self.pageInfo.pageCount === 0) {
                    
                    pageBox.style.display = "none";
                } else {
                    pageBox.style.display = "block";
                }
                _self.$emit('show', param);
            });

            var param = {
                pageCount: _self.pageInfo.pageCount,
                curPage: _self.pageInfo.pageCurrent,
                pageInfo: _self.pageInfo,
                page_func: function (p_curPage, p_pageInfo) {
                    _self.pageInfo.pageCurrent = p_curPage;
                    _self.pageInfo.curPageRecord = [];
                    _self.$http.post("/OrderExpert/GetAllActiveDoctorLists", _self.pageInfo).then(function (res) {
                        for (var i = 0; i < res.body.curPageRecord.length; i++) {
                            _self.pageInfo.curPageRecord.push(res.body.curPageRecord[i]);
                        }
                        _self.pageInfo.totalCount = res.body.totalCount;
                        _self.pageInfo.pageCount = res.body.pageCount;
                        overflowEllipsis(_self);
                    });
                }
            };
            _self.showPageParam = param;
            if (_self.pageInfo.totalCount > 0) {
                noResult.style.display = "none";
            } else {
                noResult.style.display = "block";
            }

            var pageBox = document.getElementById("clinic-page-box");
            if (_self.pageInfo.pageCount === 1 || _self.pageInfo.pageCount === 0)
                pageBox.style.display = "none";
            else
                pageBox.style.display = "block";

            _self.$emit('show', param);
            noResult.style.display = "block";
        },
        methods: {
            showPage: function (date, deptId, deptName, titleId, titleName, keyWord) {
                var _self = this;
                _self.pageInfo.date = date;
                _self.pageInfo.deptId = deptId;
                _self.pageInfo.deptName = deptName;
                _self.pageInfo.titleId = titleId;
                _self.pageInfo.titleName = titleName;
                _self.pageInfo.keyWord = keyWord;

                _self.pageInfo.pageCurrent = 1;
                _self.pageInfo.curPageRecord = [];
                _self.$http.post("/OrderExpert/GetActiveDoctorLists", _self.pageInfo).then(function (res) {
                    for (var i = 0; i < res.body.curPageRecord.length; i++) {
                        _self.pageInfo.curPageRecord.push(res.body.curPageRecord[i]);
                    }
                    _self.pageInfo.totalCount = res.body.totalCount;
                    _self.pageInfo.pageCount = res.body.pageCount;
                    _self.pageInfo.pageCurrent = res.body.pageCurrent;
                    _self.param.pageCount = res.body.pageCount;
                    _self.param.curPage = res.body.pageCurrent;
                    _self.param.pageInfo = _self.pageInfo;
                    overflowEllipsis(_self);

                    var param = {
                        pageCount: _self.pageInfo.pageCount,
                        curPage: _self.pageInfo.pageCurrent,
                        pageInfo: _self.pageInfo,
                        page_func: function (p_curPage, p_pageInfo) {
                            _self.pageInfo.pageCurrent = p_curPage;
                            _self.pageInfo.curPageRecord = [];
                            _self.$http.post("/OrderExpert/GetActiveDoctorLists", _self.pageInfo).then(function (res) {
                                for (var i = 0; i < res.body.curPageRecord.length; i++) {
                                    _self.pageInfo.curPageRecord.push(res.body.curPageRecord[i]);
                                }
                                _self.pageInfo.totalCount = res.body.totalCount;
                                _self.pageInfo.pageCount = res.body.pageCount;
                                overflowEllipsis(_self);
                            });
                        }
                    };
                    _self.showPageParam = param;
                    if (_self.pageInfo.totalCount > 0) {
                        noResult.style.display = "none";
                    } else {
                        noResult.style.display = "block";
                    }
                    var pageBox = document.getElementById("clinic-page-box");
                    if (_self.pageInfo.pageCount === 1 || _self.pageInfo.pageCount === 0)
                        pageBox.style.display = "none";
                    else
                        pageBox.style.display = "block";

                    _self.$emit('show', param);
                });

                var param = {
                    pageCount: _self.pageInfo.pageCount,
                    curPage: _self.pageInfo.pageCurrent,
                    pageInfo: _self.pageInfo,
                    page_func: function (p_curPage, p_pageInfo) {
                        _self.pageInfo.pageCurrent = p_curPage;
                        _self.pageInfo.curPageRecord = [];
                        _self.$http.post("/OrderExpert/GetActiveDoctorLists", _self.pageInfo).then(function (res) {
                            for (var i = 0; i < res.body.curPageRecord.length; i++) {
                                _self.pageInfo.curPageRecord.push(res.body.curPageRecord[i]);
                            }
                            _self.pageInfo.totalCount = res.body.totalCount;
                            _self.pageInfo.pageCount = res.body.pageCount;
                            overflowEllipsis(_self);
                        });
                    }
                };
                _self.showPageParam = param;
                if (_self.pageInfo.totalCount > 0) {
                    noResult.style.display = "none";
                } else {
                    noResult.style.display = "block";
                }

                var pageBox = document.getElementById("clinic-page-box");
                if (_self.pageInfo.pageCount === 1 || _self.pageInfo.pageCount === 0)
                    pageBox.style.display = "none";
                else
                    pageBox.style.display = "block";


                _self.$emit('show', param);
            },
            addConditions: function ($event, index, type) {
                var _self = this;
                if (type == "Date") {
                    _self.dateSatus = index;
                } else if (type == "Dept") {
                    _self.deptSatus = index;
                } else if (type == "Title") {
                    _self.titleSatus = index;
                }

                _self.condition = { Id: '', Name: '' };

                for (var i = 0; i < _self.conditionsList.length; i++) {
                    if (_self.conditionsList[i].From == type) {
                        _self.conditionsList.splice(i, 1);
                    }
                }

                _self.condition = {
                    Id: $event.currentTarget.firstElementChild.id,
                    Name: $event.currentTarget.firstElementChild.name,
                    From: type
                };

                _self.conditionsList.push(_self.condition);

                var deptitem = "";
                var dateitem = "";
                var titleitem = "";
                var deptitemname = "";
                var titleitemname = "";

                for (var i = 0; i < _self.conditionsList.length; i++) {
                    if (_self.conditionsList[i].From == "Date") {
                        dateitem = _self.conditionsList[i].Id;
                    } else if (_self.conditionsList[i].From == "Dept") {
                        deptitem = _self.conditionsList[i].Id;
                        deptitemname = _self.conditionsList[i].Name;
                    } else if (_self.conditionsList[i].From == "Title") {
                        titleitem = _self.conditionsList[i].Id;
                        titleitemname = _self.conditionsList[i].Name;
                    }
                }

                _self.showPage(dateitem, deptitem, deptitemname, titleitem, titleitemname, _self.keyword);
            },
            deleteConditions: function ($event, index) {
                var _self = this;

                for (var i = 0; i < _self.conditionsList.length; i++) {
                    if (_self.conditionsList[i].Id == $event.currentTarget.firstElementChild.id && _self.conditionsList[i].From == $event.currentTarget.firstElementChild.title) {
                        if (_self.conditionsList[i].From == "Date") {
                            _self.dateSatus = -1;
                        } else if (_self.conditionsList[i].From == "Dept") {
                            _self.deptSatus = -1;
                        } else if (_self.conditionsList[i].From == "Title") {
                            _self.titleSatus = -1;
                        }

                        _self.conditionsList.splice(i, 1);
                    }
                }

                var deptitem = "";
                var dateitem = "";
                var titleitem = "";
                var deptitemname = "";
                var titleitemname = "";

                for (var i = 0; i < _self.conditionsList.length; i++) {
                    if (_self.conditionsList[i].From == "Date") {
                        dateitem = _self.conditionsList[i].Id;
                    } else if (_self.conditionsList[i].From == "Dept") {
                        deptitem = _self.conditionsList[i].Id;
                        deptitemname = _self.conditionsList[i].Name;
                    } else if (_self.conditionsList[i].From == "Title") {
                        titleitem = _self.conditionsList[i].Id;
                        titleitemname = _self.conditionsList[i].Name;
                    }
                }

                _self.showPage(dateitem, deptitem,deptitemname, titleitem,titleitemname, _self.keyword);
            },
            moreLists: function (obj, objBox) {
                var obj = document.getElementById(obj),
                    objBox = document.getElementById(objBox);
                if (obj.getAttribute("maxHeight")) {
                    objBox.style.maxHeight = "none";
                    obj.innerHTML = "收起";
                    obj.style.background = "url(~/Styles/image/icon/moreUp_icon.png) no-repeat right center";
                    obj.removeAttribute("maxHeight");
                } else {
                    objBox.style.maxHeight = "49px";
                    obj.innerHTML = "更多";
                    obj.style.background = "url(~/Styles/image/icon/moreDown_icon.png) no-repeat right center";
                    obj.setAttribute("maxHeight", "maxHeight");
                }
            },
            GetDoctorLists: function () {
                var deptitem = "";
                var dateitem = "";
                var titleitem = "";
                var deptitemname = "";
                var titleitemname = "";
                var _self = this;

                for (var i = 0; i < _self.conditionsList.length; i++) {
                    if (_self.conditionsList[i].From == "Date") {
                        dateitem = _self.conditionsList[i].Id;
                    } else if (_self.conditionsList[i].From == "Dept") {
                        deptitem = _self.conditionsList[i].Id;
                        deptitemname = _self.conditionsList[i].Name;
                    } else if (_self.conditionsList[i].From == "Title") {
                        titleitem = _self.conditionsList[i].Id;
                        titleitemname = _self.conditionsList[i].Name;
                    }
                }

                _self.doctorList = [];
                _self.$http.post("/OrderExpert/GetActiveDoctorList",
                    { date: dateitem, deptId: deptitem, deptName: deptitemname, titleId: titleitem, titleName: titleitemname, keyWord: _self.keyword }).then(
                    function (res) {
                        for (var i = 0; i < res.body.length; i++) {
                            _self.doctorList.push(res.body[i]);
                        }
                    });

                _self.showPage(dateitem, deptitem,deptitemname, titleitem,titleitemname, _self.keyword);
            },
            doctorBooking: function ($event) {
                var _self = this;
                _self.doctorid = $event.currentTarget.id;
                var opensrc = "/ExpertDetail/Index?doctorid=" + _self.doctorid;
                window.open(opensrc);
            }
        }
    });
})(Vue)